package com.jie.other.jetpack

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.activityViewModels
import com.jie.commonlib.base.BaseFragment
import com.jie.other.databinding.OtherFragmentViewModelDetailBinding
import com.jie.other.jetpack.viewmodel.UserViewModel

class ViewModelDetailFragment : BaseFragment(){

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {

        val mViewBinding = OtherFragmentViewModelDetailBinding.inflate(inflater, container, false)
        val mViewModel by activityViewModels<UserViewModel>()
        mViewModel.getUserList().observe(viewLifecycleOwner) {
            it.forEach { bean ->
                if (bean.isSelect) {
                    mViewBinding.tvName.text = bean.name
                }
            }
        }

        return mViewBinding.root
    }

}